﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Awesomium.Core;
using System.Text.RegularExpressions;
using System.Threading;
using System.Diagnostics;

namespace Diplomova_prace
{
    public partial class Derivation_win : Form
    {
        Derivation_alg derivation = new Derivation_alg();
        Reg reg = new Reg();
        Expression expression = new Expression();
        Derivace_ret ret = new Derivace_ret();
        Methods method;
        string NameMethod;
        StringBuilder sb1 = new StringBuilder();
        string pathToHtml = string.Empty;
        readonly string temp = string.Empty;
        StreamWriter sw;
        static int instanceCounter;
        readonly int instanceId;
        string result = string.Empty;
        string formula = string.Empty;
        int defaultFontSize = 24;
        Exports export = new Exports();
        bool incorrect = false;
        SaveDialogs save = new SaveDialogs();
        public enum Methods
        {
            FirstLinearDerivation = 0,
            FirstQuadraticDerivation = 1,
            SecondDerivation = 2,
            RichardsonExtrapolation = 3
        }
        string PathToLastExportFile = string.Empty;

        public Derivation_win(Methods method, string funkce="",string bod="",string krok="",string presnost="")
        {
            this.method = method;
            this.instanceId = instanceCounter++;
            InitializeComponent();
            NameWindow();
            DisableComponents();
            AlignComponents();
            FontSize_trackBar.Value = defaultFontSize;
            this.Show();
            webControl1.Enabled = true;
            derivation.post += derivation_post;
            expression.incorrectInput += expression_incorrectInput;
            backgroundWorker1.WorkerSupportsCancellation = true;
            backgroundWorker1.DoWork += new DoWorkEventHandler(DoWork);
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Done);
            temp = MainMenu.tempProperty + "Derivation";
            this.FillListChangeMethod(ChangeMethod_ListBox,MainMenu.dictDerTagName);
            funkce_textBox.Text = funkce;
            bod_textBox.Text = bod;
            krok_textBox.Text = krok;
            presnost_textBox.Text = presnost;
        }

        void derivation_post()
        {
            if (!incorrect)
            {
                MessageBox.Show("Nekorektní vstup", "chyba", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                sw.Close();
                if (backgroundWorker1.IsBusy)
                    backgroundWorker1.CancelAsync();
            }
        }

        void expression_incorrectInput()
        {
            if (!incorrect)
            {
                MessageBox.Show("Nekorektní vstup", "chyba", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                sw.Close();
                incorrect = true;
                VypocitejButton.Enabled = true;
            }
        }

        private void DoWork(object sender, DoWorkEventArgs e)
        {
                double bod = expression.ComputeRPN(expression.RPN(bod_textBox.Text));
                double krok = expression.ComputeRPN(expression.RPN(krok_textBox.Text));
                double presnost = -1;

                if (method == Methods.FirstLinearDerivation)
                {
                    ret = derivation.LinearDerivate(funkce_textBox.Text, bod, krok);
                    result = ShowFirstLinearDerivation(ret);
                }
                else if (method == Methods.FirstQuadraticDerivation)
                {
                    ret = derivation.QudraticDerivate(funkce_textBox.Text, bod, krok);
                    result = ShowFirstQuadraticDerivation(ret);
                }
                else if (method == Methods.SecondDerivation)
                {
                    ret = derivation.QudraticSecondDerivate(funkce_textBox.Text, bod, krok);
                    result = ShowSecondDerivation(ret);
                }
                else if (method == Methods.RichardsonExtrapolation)
                {
                    presnost = expression.ComputeRPN(expression.RPN(presnost_textBox.Text));
                    ret = derivation.RichardsonovaExtrapolace(funkce_textBox.Text, bod, presnost, krok);
                    result = ShowRichardsonExtrapolation(ret);
                }
                sw.WriteLine(GenerateHtml(result));
                sw.Close();
        }

        private void Done(object sender, RunWorkerCompletedEventArgs e)
        {
            DecimalPlaces_numericUpDown.Enabled = true;
            
            VypocitejButton.Enabled = true;
            if (!incorrect)
                webControl1.Source = new Uri(Path.GetFullPath(pathToHtml));
        }

        private string ShowFirstLinearDerivation(Derivace_ret vstup)
        {
            sb1.Clear();
            sb1.Append(Mathml.HeaderMath());
            sb1.Append(Mathml.Sup(Mathml.Literal("f"), Mathml.Mo(Symbols.FirstDer)) + Mathml.Equal +
                Mathml.Frac(Mathml.Literal("f") + Mathml.LZ + vstup.xProperty.NumToMathml() + Mathml.Plus + vstup.hProperty.NumToMathml() + Mathml.PZ +
                Mathml.Minus +
                Mathml.Literal("f") + Mathml.LZ + vstup.xProperty.NumToMathml() + Mathml.PZ, vstup.hProperty.NumToMathml()));
            sb1.Append(Mathml.LineBreak);
            sb1.Append(Mathml.Sup(Mathml.Literal("f"), Mathml.Mo(Symbols.FirstDer)) + Mathml.Equal +
                Mathml.Frac(vstup.f0Property.NumToMathml() + (-1 * vstup.f1Property).NumToMathml("+", "+"), vstup.hProperty.NumToMathml()));
            sb1.Append(Mathml.Equal + vstup.Result.NumToMathml());
            sb1.Append(Mathml.EndMath);
            return sb1.ToString();
        }

        private string ShowFirstQuadraticDerivation(Derivace_ret vstup)
        {
            sb1.Clear();
            sb1.Append(Mathml.HeaderMath());
            sb1.Append(Mathml.Sup(Mathml.Literal("f"), Mathml.Mo(Symbols.FirstDer)) + Mathml.Equal +
                Mathml.Frac(Mathml.Literal("f") + Mathml.LZ + vstup.xProperty.NumToMathml() + Mathml.Plus + vstup.hProperty.NumToMathml() + Mathml.PZ +
                Mathml.Minus + Mathml.Literal("f") + Mathml.LZ + vstup.xProperty.NumToMathml() + Mathml.Minus + vstup.hProperty.NumToMathml() + Mathml.PZ,
                Mathml.Constant(2) + Mathml.Multiply + vstup.hProperty.NumToMathml()));
            sb1.Append(Mathml.LineBreak);
            sb1.Append(Mathml.Sup(Mathml.Literal("f"), Mathml.Mo(Symbols.FirstDer)) + Mathml.Equal +
                Mathml.Frac(vstup.f0Property.NumToMathml() + (-1 * vstup.f1Property).NumToMathml("+", "+"), Mathml.Constant(2) + Mathml.Multiply + vstup.hProperty.NumToMathml()));
            sb1.Append(Mathml.Equal + vstup.Result.NumToMathml());
            sb1.Append(Mathml.EndMath);
            return sb1.ToString();
        }

        private string ShowSecondDerivation(Derivace_ret vstup)
        {
            sb1.Clear();
            sb1.Append(Mathml.HeaderMath());
            sb1.Append(Mathml.Sup(Mathml.Literal("f"), Mathml.Mo(Symbols.SecondDer)) + Mathml.Equal +
                Mathml.Frac(Mathml.Literal("f") + Mathml.LZ + vstup.xProperty.NumToMathml() + Mathml.Plus + vstup.hProperty.NumToMathml() + Mathml.PZ +
                Mathml.Minus + Mathml.Constant(2) + Mathml.Multiply + Mathml.Literal("f") + Mathml.LZ + vstup.xProperty.NumToMathml() + Mathml.PZ +
                Mathml.Plus + Mathml.Literal("f") + Mathml.LZ + vstup.xProperty.NumToMathml() + Mathml.Minus + vstup.hProperty.NumToMathml() + Mathml.PZ,
                Mathml.Sup(vstup.hProperty.NumToMathml(), Mathml.Constant(2))));
            sb1.Append(Mathml.LineBreak);
            sb1.Append(Mathml.Sup(Mathml.Literal("f"), Mathml.Mo(Symbols.SecondDer)) + Mathml.Equal +
                Mathml.Frac(vstup.f0Property.NumToMathml() + Mathml.Minus + Mathml.Constant(2) + Mathml.Multiply + vstup.f1Property.Bracket() + vstup.f2Property.NumToMathml("+", "+"), Mathml.Sup(vstup.hProperty.NumToMathml(), Mathml.Constant(2))));
            sb1.Append(Mathml.Equal + vstup.Result.NumToMathml());
            sb1.Append(Mathml.EndMath);
            return sb1.ToString();
        }

        private string ShowRichardsonExtrapolation(Derivace_ret vstup)
        {
            return (Mathml.HeaderMath() + Mathml.Table(vstup.RichardsonProperty) + Mathml.EndMath);
        }

        private void vypocitej_button_Click(object sender, EventArgs e)
        {
            RemoveHtmlInstance();
            VypocitejButton.Enabled = false;
            FontSize_trackBar.Value = defaultFontSize;
            DecimalPlaces_numericUpDown.Enabled = false;
            exportyToolStripMenuItem.Enabled = false;
            incorrect = false;
            TimeSpan ts = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            pathToHtml = temp + instanceId + method.ToString() + ts.TotalSeconds.ToString() + ".html";
            toolStripStatusLabel1.Text = string.Empty;
            toolStripSplitButton1.Visible = false;
            this.sw = new StreamWriter(pathToHtml);
            VypocitejButton.Enabled = false;
            if (CheckInput(true))
                sw.Close();
        }

        private void funkce_textBox_TextChanged(object sender, EventArgs e)
        {
            CheckFillTextBoxs();
        }

        private void bod_textBox_TextChanged(object sender, EventArgs e)
        {
            CheckFillTextBoxs();
        }

        private void krok_textBox_TextChanged(object sender, EventArgs e)
        {
            CheckFillTextBoxs();
        }

        private void presnost_textBox_TextChanged(object sender, EventArgs e)
        {
            CheckFillTextBoxs();
        }

        private bool CheckInput(bool RunWorker)
        {
            this.RemoveSpacesFromTextBoxs();
            string checkInfinity = this.CheckTextBoxsInfinity(expression);
            if (checkInfinity != string.Empty)
            {
                MessageBox.Show("Ve vstupních datech je nastavena nedefinovaná hodnota (" + (checkInfinity) + ")", "Nedefinovaná hodnota", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (!reg.Check(funkce_textBox.Text))
            {
                MessageBox.Show("Špatně zadaná funkce", "Funkce", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (!reg.Check(bod_textBox.Text))
            {
                MessageBox.Show("Špatně zadaný bod", "Bod", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (!reg.Check(krok_textBox.Text))
            {
                MessageBox.Show("Špatně zadaný krok", "Krok", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                DecimalPlaces_numericUpDown.Enabled = true;
                VypocitejButton.Enabled = true;
                return true;
            }
            if (!funkce_textBox.Text.Contains('x'))
            {
                MessageBox.Show("Musí být zadána funkce", "Funkce", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                DecimalPlaces_numericUpDown.Enabled = true;
                VypocitejButton.Enabled = true;
                
                return true;
            }
            if (bod_textBox.Text.Contains('x'))
            {
                MessageBox.Show("Špatně zadaný bod", "Bod", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (krok_textBox.Text.Contains('x'))
            {
                MessageBox.Show("Špatně zadaný krok", "Krok", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (!reg.Check(presnost_textBox.Text))
            {
                MessageBox.Show("Špatně zadaná přesnost", "Přesnost", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (presnost_textBox.Text.Contains('x'))
            {
                MessageBox.Show("Musí být zadána číselná hodnota", "Přesnost", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (method ==Methods.RichardsonExtrapolation && expression.ComputeRPN(expression.RPN(presnost_textBox.Text)) <= 0)
            {
                MessageBox.Show("Přesnost musí být kladná hodnota", "Přesnost", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (expression.ComputeRPN(expression.RPN(krok_textBox.Text)) <= 0)
            {
                MessageBox.Show("Krok musí být kladná hodnota", "Krok", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                
                VypocitejButton.Enabled = true;
                DecimalPlaces_numericUpDown.Enabled = true;
                return true;
            }
            if (!incorrect && RunWorker)
                backgroundWorker1.RunWorkerAsync();
            return false;
        }

        private void CheckFillTextBoxs()
        {
            if ((int)method < 3)
            {
                if (funkce_textBox.Text != string.Empty && krok_textBox.Text != string.Empty && bod_textBox.Text != string.Empty)
                {
                    AddTask_Button.Enabled = true;
                    VypocitejButton.Enabled = true;
                }
                else
                {
                    AddTask_Button.Enabled = false;
                    VypocitejButton.Enabled = false;
                }
            }
            else
            {
                if (funkce_textBox.Text != string.Empty && krok_textBox.Text != string.Empty && bod_textBox.Text != string.Empty && presnost_textBox.Text !=string.Empty)
                {
                    AddTask_Button.Enabled = true;
                    VypocitejButton.Enabled = true;
                }
                else
                {
                    AddTask_Button.Enabled = false;
                    VypocitejButton.Enabled = false;
                }
            }
        }

        private string GenerateHtml(string input)
        {
                string currDirectory = Directory.GetCurrentDirectory();
                StringBuilder divInput = new StringBuilder(Html.Div() + Html.Span("Byla zadána funkce:    ") + Mathml.HeaderMath(Mathml.Display.inline) + Mathml.Literal("f") + Mathml.LZ + Mathml.Literal("x") + Mathml.PZ + Mathml.Equal + Mathml.Space() + Mathml.EndMath + expression.TextToMathml(funkce_textBox.Text, Mathml.Display.inline) 
                    + Html.Span(".")+Html.Br);
                if ( method !=Methods.SecondDerivation)
                    divInput.Append(Html.Span(" Úkolem je určit hodnotu první derivace v bodě:    ")); 
                else
                    divInput.Append(Html.Span(" Úkolem je určit hodnotu druhé derivace v bodě:    ")); 
                divInput.Append(expression.TextToMathml(bod_textBox.Text,Mathml.Display.inline)
                    +Html.Span(" s krokem:     ")+expression.TextToMathml(krok_textBox.Text,Mathml.Display.inline));
                if ( method ==Methods.RichardsonExtrapolation)
                    divInput.Append(Html.Span(" a přesností:    ") + expression.TextToMathml(presnost_textBox.Text,Mathml.Display.inline)+Html.Span("."));
                else
                    divInput.Append(Html.Span("."));
                divInput.Append(Html.Br);
                divInput.Append(Html.Span("Předpis zvolené metody:")+Html.Br+ formula + Html.Br);
                divInput.Append(Html.Span("Výsledek")+Html.Br+Html.EndDiv);
                input = Html.Div() + input + Html.EndDiv;
                result = Html.HeaderHTML(NameMethod) + divInput.ToString() + input + Html.EndHTML;
                return result;  
        }

        private void AlignComponents()
        {
            int centerPanel = splitContainer1.Panel1.Width / 2;
            if ((int)method < 3)
                VypocitejButton.Location = new Point(centerPanel - VypocitejButton.Size.Width / 2, presnost_textBox.Location.Y);
        }

        private void DisableComponents()
        {
            if ((int)method < 3)
            {
                presnost_textBox.Visible = false;
                presnost_label.Visible = false;
            }
        }

        private void NameWindow()
        {
            if (method == Methods.FirstLinearDerivation)
            {
                this.Text = "První lineární derivace";
                formula = Formulas.FirstLinearDerivation;
            }
            else if (method == Methods.FirstQuadraticDerivation)
            {
                this.Text = "První kvadratická derivace";
                formula = Formulas.FirstQuadraticDerivation;
            }
            else if (method == Methods.SecondDerivation)
            {
                this.Text = "Druhá derivace";
                formula = Formulas.SecondDerivation;
            }
            else if (method == Methods.RichardsonExtrapolation)
            {
                this.Text = "Richardsonova extrapolace";
                formula = Formulas.RichardsonExtrapolation;
            }
            NameMethod = this.Text;
        }

        private void RemoveHtmlInstance()
        {
            string directory = Directory.GetCurrentDirectory();
            List<string> files = Directory.GetFiles(directory).ToList();
            foreach (string file in files)
            {
                if (file.Contains(temp + instanceId + method.ToString()))
                {
                    File.Delete(Path.GetFullPath(file));
                }
            }
        }

        private void Derivation_win_FormClosing(object sender, FormClosingEventArgs e)
        {
            RemoveHtmlInstance();   
        }

        private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
        {
            webControl1.Reload(true);
            FontSize_trackBar.Value = defaultFontSize;
        }

        private void xMLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (save.SaveAsXML(result))
            {
                toolStripStatusLabel1.Text = Path.GetFileName(save.PathToDestinationFileProperty) + " soubor byl vytvořen";
                toolStripSplitButton1.Visible = true;
                PathToLastExportFile = save.PathToDestinationFileProperty;
            }
        }

        private void hTMLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (save.SaveAsHTML(result))
            {
                toolStripStatusLabel1.Text = Path.GetFileName(save.PathToDestinationFileProperty) + " soubor byl vytvořen";
                toolStripSplitButton1.Visible = true;
                PathToLastExportFile = save.PathToDestinationFileProperty;
            }
        }

        private void FontSize_trackBar_Scroll(object sender, EventArgs e)
        {
            string size = FontSize_trackBar.Value.ToString();
            webControl1.ExecuteJavascript("changeSize('" + size + "px')");
        }

        private void Awesomium_Windows_Forms_WebControl_DocumentReady(object sender, Awesomium.Core.UrlEventArgs e)
        {
            FontSize_trackBar.Enabled = true;
            while (!webControl1.ExecuteJavascriptWithResult("IsCompleted()")) ;
            exportyToolStripMenuItem.Enabled = true;
        }

        private void imageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (result != string.Empty)
            {
                int width = int.Parse(webControl1.ExecuteJavascriptWithResult("WidthDiv()"));
                int height = int.Parse(webControl1.ExecuteJavascriptWithResult("HeightDiv()"));
                int fontSize = FontSize_trackBar.Value;
                if (save.SaveAsImage(result, width, height, fontSize, pathToHtml))
                {
                    toolStripStatusLabel1.Text = Path.GetFileName(save.PathToDestinationFileProperty) + " soubor byl vytvořen";
                    toolStripSplitButton1.Visible = true;
                    PathToLastExportFile = save.PathToDestinationFileProperty;
                }
            }
        }

        private void FontSize_trackBar_MouseUp(object sender, MouseEventArgs e)
        {
            string size = FontSize_trackBar.Value.ToString();
            webControl1.ExecuteJavascript("changeSize('" + size + "px')");
            toolStripStatusLabel1.Text = string.Empty;
        }

        private void FontSize_trackBar_KeyDown(object sender, KeyEventArgs e)
        {
            string size = FontSize_trackBar.Value.ToString();
            webControl1.ExecuteJavascript("changeSize('" + size + "px')");
            toolStripStatusLabel1.Text = string.Empty;
        }

        private void pDFToolStripMenuItem_Click(object sender, EventArgs e)
        {
        /*    if (result != string.Empty)
            {
                int width = int.Parse(webControl1.ExecuteJavascriptWithResult("WidthDiv()"));
                int height = int.Parse(webControl1.ExecuteJavascriptWithResult("HeightDiv()"));
                int fontSize = FontSize_trackBar.Value;
                if (save.SaveAsPDF(result, width, height, fontSize))
                {
                    toolStripStatusLabel1.Text = Path.GetFileName(save.PathToDestinationFileProperty) + " soubor byl vytvořen";
                    toolStripSplitButton1.Visible = true;
                    PathToLastExportFile = save.PathToDestinationFileProperty;
                }
            }*/
        }

        private void DecimalPlaces_numericUpDown_ValueChanged(object sender, EventArgs e)
        {
            Extension.countDecimalPlaces = (int)DecimalPlaces_numericUpDown.Value;
        }

        private void AddTask_button_Click(object sender, EventArgs e)
        {
            if (!CheckInput(false))
                AddTask();
        }

        private void AddTask()
        {
            DateTime date = DateTime.Now;
            string file = date.ToString("yyyyMMddHHmmss") + ".xml";
            string[] Files = Directory.GetFiles(Directory.GetCurrentDirectory() + MainMenu.PathTaskDerProperty + MainMenu.dictDerTagName[(int)method]);
            string path = Directory.GetCurrentDirectory() + MainMenu.PathTaskDerProperty + MainMenu.dictDerTagName[(int)method] + "\\" + file;
            StreamWriter stw = new StreamWriter(path);
            stw.WriteLine("<?xml version='1.0' encoding='UTF-8'?>");
            stw.WriteLine("<uloha>");

            stw.WriteLine("<funkce>" + funkce_textBox.Text + "</funkce>");
            stw.WriteLine("<bod>" + bod_textBox.Text + "</bod>");
            stw.WriteLine("<krok>" + krok_textBox.Text + "</krok>");
            if (presnost_textBox.Visible && presnost_textBox.Text != string.Empty)
                stw.WriteLine("<presnost>" + presnost_textBox.Text + "</presnost>");
            stw.WriteLine("</uloha>");
            stw.Close();
            StreamReader sr = new StreamReader(Directory.GetCurrentDirectory() + MainMenu.PathTaskDerProperty + MainMenu.dictDerTagName[(int)method] + "\\" + file);
            string tmp = sr.ReadToEnd().Trim();
            foreach (string item in Files)
            {
                StreamReader str = new StreamReader(item);

                string tmp1 = str.ReadToEnd().Trim();
                if (tmp == tmp1)
                {
                    MessageBox.Show("Tato úloha byla již přidána", "Existující úloha", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    str.Close();
                    sr.Close();
                    File.Delete(Directory.GetCurrentDirectory() + MainMenu.PathTaskDerProperty + MainMenu.dictDerTagName[(int)method] + "\\" + file);
                    return;
                }
                str.Close();
            }
            sr.Close();

            toolStripStatusLabel1.Text = "Úloha byla přidána do cvičných úloh";
        }

        private void ChangeMethod_ListBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Derivation_win derivation;
            if (ChangeMethod_ListBox.SelectedIndex > -1)
                derivation = new Derivation_win((Methods)ChangeMethod_ListBox.SelectedIndex,
                    (funkce_textBox.Visible) ? funkce_textBox.Text : string.Empty,
                    (bod_textBox.Visible) ? bod_textBox.Text : string.Empty,
                    (krok_textBox.Visible) ? krok_textBox.Text : string.Empty,
                    (presnost_textBox.Visible) ? presnost_textBox.Text : string.Empty);
        }

        private void FontSize_trackBar_MouseUp_1(object sender, MouseEventArgs e)
        {
            string size = FontSize_trackBar.Value.ToString();
            webControl1.ExecuteJavascript("changeSize('" + size + "px')");
            toolStripStatusLabel1.Text = string.Empty;
        }

        private void FontSize_trackBar_KeyUp(object sender, KeyEventArgs e)
        {
            string size = FontSize_trackBar.Value.ToString();
            webControl1.ExecuteJavascript("changeSize('" + size + "px')");
            toolStripStatusLabel1.Text = string.Empty;
        }

        private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e)
        {
            Process.Start(PathToLastExportFile);
        }

        private void toolStripSplitButton1_MouseHover(object sender, EventArgs e)
        {
            statusStrip.ShowItemToolTips = true;
            toolStripSplitButton1.ToolTipText = "otevřít soubor";
        }



    }
}
